<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/


namespace Member\Model;
use Think\Model;
use \Org\Util\String;
    
class MemberWorksModel extends Model {

	//protected $insertFields = array('username','usertype','typename','password','powercode','usergroup','groupname','email','unionid','uniontime','regip','dateline','mobile');
	
	//protected $updateFields = array('avatar','SecurityForm');
	
	//字段过滤-----------------------------------------------------------------------------------------------
	//protected $insertFields = array('title','status','rules','icon','color','allowdomainname','allowlogin','allowskillnumber','allowsendsms','feetype','taskfee','SecurityForm');
	//protected $updateFields = array('usertype','typename','password','powercode','usergroup','groupname','email','unionid','uniontime','regip','dateline','mobile','birthday','about','gender','area','phone','qq','provid','cityid','distid','provname','cityname','distname','address','SecurityForm');
	
	
	//字段检查-----------------------------------------------------------------------------------------------
	protected $_validate = array(
		//array('title','require','请输入名称！'),
	);
	
	//数据过滤-----------------------------------------------------------------------------------------------
	function FormatData(){

		$data['uid']=$this->uid;
		$data['starttime']=strtotime(intval($_POST['starttime']).'-1-1');
		$data['endtime']=strtotime(intval($_POST['endtime']).'-1-1');
		$data['company']=String::msubstr(I('post.company','','string'),0,120,C('S_CHARSET'),false);
		$data['job']=String::msubstr(I('post.job'),0,30,C('S_CHARSET'),false);
		$data['description']=String::msubstr(I('post.description','','string'),0,200,C('S_CHARSET'),false);

		//所在地---------------------------------------------------------------------------------
		$provid=$data['provid']=intval($_POST['provid']);
		
		$cityid=$data['cityid']=intval($_POST['cityid']);
		
		$distid=$data['distid']=intval($_POST['distid']);
		
		if($provid && $cityid && $distid){
		
			$provnamearr=M('CategoryCity')->where("catid=$provid")->find();
			
			$citynamearr=M('CategoryCity')->where("catid=$cityid")->find();
			
			$distnamearr=M('CategoryCity')->where("catid=$distid")->find();
			
			$data['provname']=$provnamearr['name'];
			
			$data['cityname']=$citynamearr['name'];
			
			$data['distname']=$distnamearr['name'];
		
		}
			
		$data['SecurityForm']=I('post.SecurityForm','','string');
		return $data;
	}
	
	//获取用户使用条数
	function GetCountWorks(){
		return intval($this->where(" uid=$this->uid ")->count("uid"));
	}

	//获取一维数据
	function GetArrayWorks($id=0){
		$id=!empty($id) ? intval($id) : 0 ;
		$result=$this->where(" id=$id ")->find();
		if(intval($result['id'])>0){
			return $result;
		}else{
			$this->error='数据不存在或有误!';
			return false;
		}
	}
	
	//获取会员所有数据
	function GetArrayAllWorks(){
		$result=$this->where(" uid=$this->uid ")->limit(5)->order('id ASC')->select();
		if(is_array($result)){
			return $result;
		}else{
			$this->error='数据不存在或有误!';
			return false;
		}
	}
	
	//修改信息
	function EditMemberWorks(){
		$id=intval($_POST['id']);
		if ($this->create($this->FormatData())){
			if($this->where(" id=$id ")->save()){
				return true;
			}
		}
		$this->error=$this->getError();
		return false;
	}
	
	//删除信息
	function DeleteMemberWorks(){
		$id=intval($_POST['id']);
		if($id){
			$this->where(" id=$id ")->delete();
			return true;
		}else{
			return false;
		}
	}
	
	//插入信息
	function InsertMemberWorks(){
		if($this->GetCountWorks()<5){
			if ($this->create($this->FormatData())){
				if($this->add()){
					return true;
				}
			}
			$this->error=$this->getError();
			return false;
		}else{
			$this->error='您已经添加5条了!';
			return false;
		}
	}

	
}

?>